﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using SaveMeWCF;
using Backend;
using DBLayer;
using System.Net;
using System.IO;
using System.Xml;


namespace TestWCF
{
    [TestClass]
    public class TestTheWCF
    {
        [TestMethod()]
        public void TestInitiate()
        {   DBTaxiRequest dbTaxiRequest =new DBTaxiRequest();
            TaxiRequest taxiRequest = new TaxiRequest();
            //taxiRequest.Id = GetMax.GetMaxId();
            //taxiRequest.PhoneNr="898988";
            //    taxiRequest.Status=1;
             //   taxiRequest.Date = DateTime.Now.ToString();
                taxiRequest.Address = "Prinsensgade";
                string url = "http://balder.ucn.dk/dm77_gr2/SaveMe.svc/SendMyLocation/" + taxiRequest.Address;
                XmlDocument xmlDoc = MakeRequest(url);

                String theFuckingResponse = xmlDoc.FirstChild.InnerText;

          

    

                Assert.AreEqual(Int16.Parse(theFuckingResponse), GetMax.GetMaxId());
        }

        private static XmlDocument MakeRequest(string requestUrl)
        {
            try
            {
                HttpWebRequest request = WebRequest.Create(requestUrl) as HttpWebRequest;
                HttpWebResponse response = request.GetResponse() as HttpWebResponse;

                XmlDocument xmlDoc = new XmlDocument();
                xmlDoc.Load(response.GetResponseStream());
                return (xmlDoc);

            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);

                Console.Read();
                return null;
            }
        }


      


    }
}
